package com.zq.recruit.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zq.common.util.Result;
import com.zq.recruit.dao.entity.DeliveryRecord;
import com.zq.recruit.dao.entity.JobPosition;
import com.zq.recruit.service.DeliveryRecordService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author 张乔
 * @Date 2025/4/5 21:33
 */
@RestController
@RequestMapping("/recruit/deliveryRecord")
public class DeliveryRecordController {

    @Resource
    private DeliveryRecordService deliveryRecordService;


@PostMapping("/add")
    public Result<Object> add(@RequestBody DeliveryRecord deliveryRecord){
deliveryRecord.setCreateTime(new Date());
 deliveryRecord.setUpdateTime(new Date());
  deliveryRecordService.save(deliveryRecord);
  return Result.success();
}

@GetMapping("/getInfoByUserId/{id}")
    public Result<Object> getInfoByUserId(@PathVariable("id") Integer id){
    List<JobPosition>  list= deliveryRecordService.getInfoByUserId(id);
       return Result.successData(list);
    }

    @GetMapping("/getInfoByJobId/{id}")
    public Result<Object> getInfoByJobId(@PathVariable("id") Integer id){
        List<JobPosition>  list= deliveryRecordService.getInfoByJobId(id);
        return Result.successData(list);
    }

    @GetMapping("/getAllInfoByJob")
    public Result<Object> getAllInfoByJob(){
        List<JobPosition>  list= deliveryRecordService.getAllInfoByJob();
        return Result.successData(list);
    }





    @DeleteMapping("/deleteById/{jobId}/{userId}")
    public Result<Object> deleteIds(@PathVariable("jobId") Integer jonId
            ,@PathVariable("userId") Integer userId){
        LambdaQueryWrapper<DeliveryRecord> lambdaQuery = new LambdaQueryWrapper<>();
        lambdaQuery.eq(jonId!=null,DeliveryRecord::getJobId,jonId)
                .eq(userId!=null,DeliveryRecord::getUserId,userId);
        deliveryRecordService.remove(lambdaQuery);
        return     Result.success();
    }





}
